var e = require("../../@babel/runtime/helpers/toConsumableArray"),
  t = require("../../@babel/runtime/helpers/slicedToArray"),
  r = require("../../@babel/runtime/helpers/regeneratorRuntime"),
  n = require("../../@babel/runtime/helpers/asyncToGenerator"),
  i = require("../../store/index"),
  o = require("../../core/mini-redux/index"),
  u = require("./data"),
  a = require("./utils"),
  s = $.getMenuButtonBoundingClientRect(),
  c = s.top,
  l = s.height;
Page((0, o.connectPage)((function (e) {
  var t;
  return {
    userInfo: e.user.userInfo,
    isLogin: !(null === (t = e.storage.userInfo) || void 0 === t || !t.token)
  }
}))({
  data: {
    headerStyle: {
      paddingTop: c,
      height: l
    },
    waitAuditCount: 0,
    waitJudgeCount: 0,
    waitPayCount: 0,
    record: u.RECORD,
    isSalesman: 0,
    banner: [],
    modules: [],
    todoList: {
      title: "我的待办",
      item: [{
          title: "待审批",
          jump_url: "/subpackage/todo/approval/index",
          num: 0,
          icon: "https://excavator-container.oss-cn-hangzhou.aliyuncs.com/file/%E5%AE%A1%E6%89%B9.png"
        },
        {
          title: "待付款",
          num: 0,
          jump_url: "/subpackage/todo/topay/index",
          icon: "https://excavator-container.oss-cn-hangzhou.aliyuncs.com/file/%E5%BE%85%E4%BB%98%E6%AC%BE.png"
        },
        {
          title: "待评价",
          num: 0,
          jump_url: "/subpackage/todo/score/index",
          icon: "https://excavator-container.oss-cn-hangzhou.aliyuncs.com/file/%E5%BE%85%E8%AF%84%E4%BB%B7.png"
        }
      ]
    },
    dailyList: {
      title: "日常办公",
      item: [{
          title: "业务员",
          jump_url: "/subpackage/rent/rent-list/index?type=1",
          icon: "https://excavator-container.oss-cn-hangzhou.aliyuncs.com/file/icon_%E5%AE%A2%E6%88%B7%E6%95%B0%E6%8D%AE%E4%BF%AE%E6%94%B9%20%281%29.png"
        }, {
          title: "甲方业主",
          jump_url: "/subpackage/rent/rent-list/index?type=2",
          icon: "https://excavator-container.oss-cn-hangzhou.aliyuncs.com/file/%E6%95%91%E6%8F%B4%E4%BA%BA%E5%91%98%20%281%29.png"
        },
        {
          title: "机械主",
          jump_url: "/subpackage/rent/rent-list/index?type=3",
          icon: "https://excavator-container.oss-cn-hangzhou.aliyuncs.com/file/%E8%93%9D%E9%A2%86-%E6%9C%BA%E6%A2%B0%20%281%29.png"
        },
        {
          title: "驾驶员",
          jump_url: "/subpackage/rent/rent-list/index?type=4",
          icon: "https://excavator-container.oss-cn-hangzhou.aliyuncs.com/file/100_driver%20%281%29.png"
        },
        {
          title: "打卡",
          jump_url: "/subpackage/clock-in/list/index",
          icon: "https://excavator-container.oss-cn-hangzhou.aliyuncs.com/file/%E8%80%83%E5%8B%A4%E6%89%93%E5%8D%A1%20%281%29.png"
        }
      ]
    },
  },
  onShow: function () {
    this.getCount()

  },
  getUserInfo() {
    var that = this;
    $.request["GET/auth/info"]().then(res => {
      var code = res[0].code
      var data = res[0].data
      if (code === 20002) {
        that.setData({
          userInfo: data,
          isSalesman: data.isSalesman
        })
        if (!data.isSalesman) {
          that.setData({
            dailyList: {
              title: "日常办公",
              item: [{
                  title: "甲方业主",
                  jump_url: "/subpackage/rent/rent-list/index?type=2",
                  icon: "https://mp-78644cf8-2fa7-4805-8999-9c23996903e0.cdn.bspapp.com/救援人员.png"
                },
                {
                  title: "机械主",
                  jump_url: "/subpackage/rent/rent-list/index?type=3",
                  icon: "https://mp-78644cf8-2fa7-4805-8999-9c23996903e0.cdn.bspapp.com/蓝领-机械.png"
                },
                {
                  title: "驾驶员",
                  jump_url: "/subpackage/rent/rent-list/index?type=4",
                  icon: "https://mp-78644cf8-2fa7-4805-8999-9c23996903e0.cdn.bspapp.com/100_driver.png"
                },
                {
                  title: "打卡",
                  jump_url: "/subpackage/clock-in/list/index",
                  icon: "https://mp-78644cf8-2fa7-4805-8999-9c23996903e0.cdn.bspapp.com/考勤打卡.png"
                }
              ]
            }
          })
        } else {
          that.setData({
            dailyList: {
              title: "日常办公",
              item: [{
                  title: "业务员",
                  jump_url: "/subpackage/rent/rent-list/index?type=1",
                  icon: "https://mp-78644cf8-2fa7-4805-8999-9c23996903e0.cdn.bspapp.com/icon_客户数据修改.png"
                }, {
                  title: "甲方业主",
                  jump_url: "/subpackage/rent/rent-list/index?type=2",
                  icon: "https://mp-78644cf8-2fa7-4805-8999-9c23996903e0.cdn.bspapp.com/救援人员.png"
                },
                {
                  title: "机械主",
                  jump_url: "/subpackage/rent/rent-list/index?type=3",
                  icon: "https://mp-78644cf8-2fa7-4805-8999-9c23996903e0.cdn.bspapp.com/蓝领-机械.png"
                },
                {
                  title: "驾驶员",
                  jump_url: "/subpackage/rent/rent-list/index?type=4",
                  icon: "https://mp-78644cf8-2fa7-4805-8999-9c23996903e0.cdn.bspapp.com/100_driver.png"
                },
                {
                  title: "打卡",
                  jump_url: "/subpackage/clock-in/list/index",
                  icon: "https://mp-78644cf8-2fa7-4805-8999-9c23996903e0.cdn.bspapp.com/考勤打卡.png"
                }
              ]
            }
          })

        }
        console.log(that.data.isSalesman)
      }
    })
  },
  getCount() {
    $.request['GET/business/engineering/log/approve/count']().then(res => {
      res = res[0]
      if (res.code == 20002) {
        this.setData({
          waitAuditCount: res.data.waitAuditCount,
          waitJudgeCount: res.data.waitJudgeCount,
          waitPayCount: res.data.waitPayCount,
          'todoList.item[0].num': res.data.waitAuditCount > 99 ? "99+" : res.data.waitAuditCount,
          'todoList.item[1].num': res.data.waitJudgeCount > 99 ? "99+" : res.data.waitJudgeCount,
          'todoList.item[2].num': res.data.waitPayCount > 99 ? "99+" : res.data.waitPayCount,
        })
        this.getUserInfo()
      }
    })
  },
  requestMemberData: function () {
    var e = this;
    return n(r().mark((function t() {
      var n, o, u, s, c, l;
      return r().wrap((function (t) {
        for (;;) switch (t.prev = t.next) {
          case 0:
            return t.prev = 0, t.next = 3, (0, i.dispatch)(i.actions.userActions.fetchUserInfo({}));
          case 3:
            c = t.sent, l = (0, a.getRecord)([null !== (n = c.coin_balance) && void 0 !== n ? n : 0, null !== (o = c.collect_number) && void 0 !== o ? o : 0, null !== (u = c.view_number) && void 0 !== u ? u : 0, null !== (s = c.contact_number) && void 0 !== s ? s : 0]), e.setData({
              record: l
            }), t.next = 11;
            break;
          case 8:
            t.prev = 8, t.t0 = t.catch(0), console.error(t.t0);
          case 11:
          case "end":
            return t.stop()
        }
      }), t, null, [
        [0, 8]
      ])
    })))()
  },
  goMemberPage: function () {
    $.router.push("/subpackage/personal/member/index")
  },
  goMyRecordPage: function (e) {
    $.router.push(e.detail)
  },
  onPullDownRefresh: function () {
    this.requestMemberData().finally((function () {
      wx.stopPullDownRefresh()
    }))
  },
  getModuleConfig: function () {
    var i = this;
    return n(r().mark((function n() {
      var o, u, a, s, c, l, d;
      return r().wrap((function (r) {
        for (;;) switch (r.prev = r.next) {
          case 0:
            return r.next = 2, $.request["GET/v2/setting/module-config"]({
              source: "XCX"
            });
          case 2:
            o = r.sent, u = t(o, 1), 200 === (a = u[0]).code && (c = a.content, console.log(c), l = (null === (s = c.find((function (e) {
              return 1 == e.module_site
            }))) || void 0 === s ? void 0 : s.item) || [], (d = c.filter((function (e) {
              return 1 != e.module_site
            }))).forEach((function (t) {
              3 === t.module_site && (t.item = [].concat(e(t.item), e(i.data.menuConfig)))
            })), i.setData({
              banner: l,
              modules: d
            }));
          case 6:
          case "end":
            return r.stop()
        }
      }), n)
    })))()
  }
}));